import 'package:common_utils/common_utils.dart';
import 'package:dss_base/dss_base.dart';
import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_demo_test/data/bean/goods_bean.dart';
import 'package:flutter_demo_test/data/respository/test_repository.dart';
import 'package:flutter_demo_test/pages/network/net_c_page.dart';

class NetBPage extends StatefulWidget {
  const NetBPage({super.key});

  @override
  State<StatefulWidget> createState() => _NetBPageState();
}

class _NetBPageState extends BasePageState<NetBPage, NetBViewModel> {
  @override
  NetBViewModel onCreateViewModel() => NetBViewModel();

  @override
  PreferredSizeWidget? onCreateAppbar(BuildContext context) {
    return AppBarX(title: '需要初始化数据');
  }

  @override
  Widget onCreateSuccessPage(BuildContext context, ScrollPhysics? physics) {
    // return ListView(
    //   physics: physics,
    //   children: [
    //     ElevatedButton(
    //       onPressed: ()=> NavigatorUtil.push(()=>NetCPage()),
    //       child: Text('下个界面'),
    //     ),
    //     Center(
    //       child: Text(viewModel.pageData?.goodsName ?? ''),
    //     )
    //   ],
    // );
    return Center(
      child: ElevatedButton(
        onPressed: ()=> NavigatorUtil.push(()=>NetCPage()),
        child: Text('下个界面'),
      ),
    );
  }
}

class NetBViewModel extends BasePageViewModel<GoodsBean> {
  @override
  bool onCheckEmpty(BaseEntity entity, GoodsBean? data) => data == null;

  @override
  GoodsBean? onConvertPageData(json) => GoodsBean.fromJson(json);

  @override
  Future<BaseEntity> onRequestPageData(int pageIndex) => TestRepository().getGoodsName('1255');
}
